//
//  ButtonView.m
//  NewMusic
//
//  Created by dllo on 15/11/14.
//  Copyright © 2015年 Going. All rights reserved.
//

#import "ButtonView.h"
#define RectY 10
#define widthNum 30
@interface ButtonView ()
@property (nonatomic, assign) NSInteger Lovenum;
@property (nonatomic, retain) UIImageView *loveImageV;
@property (nonatomic, retain) UIImageView *turnImageV;
@property (nonatomic, retain) UIImageView *songImageV;
@property (nonatomic, retain) UIImageView *shareImageV;
@property (nonatomic, retain) UIImageView *listImageV;

@end

@implementation ButtonView

- (void)dealloc
{
    [_loveImageV release];
    [_turnImageV release];
    [_songImageV release];
    [_shareImageV release];
    [_listImageV release];
    [super dealloc];
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self creatSubView];
    }
    return self;
}
- (void)creatSubView
{
    self.loveImageV = [[UIImageView alloc] initWithFrame:CGRectMake(22.5, RectY, widthNum, widthNum)];
    self.loveImageV.image = [UIImage imageNamed:@"BF-love1"];
    self.loveImageV.userInteractionEnabled = YES;
    [self addSubview:self.loveImageV];
    [_loveImageV release];
    
    self.turnImageV = [[UIImageView alloc] initWithFrame:CGRectMake(97.5, RectY, widthNum, widthNum)];
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults]; // 判断第几次使用
    NSString *str = [user stringForKey:@"turn"];
    if (0 == str.length)
    {
        [user setObject:@"list" forKey:@"turn"];
        self.turnImageV.image = [UIImage imageNamed:@"BF-liebiaoxunhuan"];
    } else {
        if ([str isEqual:@"list"])
        {
            self.turnImageV.image = [UIImage imageNamed:@"BF-liebiaoxunhuan"];
        } else if ([str isEqual:@"only"]) {
            self.turnImageV.image = [UIImage imageNamed:@"BF-danqu"];
        } else {
            self.turnImageV.image = [UIImage imageNamed:@"BF-suiji"];
        }
    }
    self.turnImageV.userInteractionEnabled = YES;
    [self addSubview:self.turnImageV];
    [_turnImageV release];
    
    self.songImageV = [[UIImageView alloc] initWithFrame:CGRectMake(172.5, RectY, widthNum, widthNum)];
    self.songImageV.image = [UIImage imageNamed:@"BF-maike"];
    self.songImageV.userInteractionEnabled = YES;
    [self addSubview:self.songImageV];
    [_songImageV release];
    
    self.shareImageV = [[UIImageView alloc] initWithFrame:CGRectMake(247.5, RectY, widthNum, widthNum)];
    self.shareImageV.image = [UIImage imageNamed:@"BF-share"];
    self.shareImageV.userInteractionEnabled = YES;
    [self addSubview:self.shareImageV];
    [_shareImageV release];
    
    self.listImageV = [[UIImageView alloc] initWithFrame:CGRectMake(322.5, RectY, widthNum, widthNum)];
    self.listImageV.image = [UIImage imageNamed:@"BF-gedan"];
    self.listImageV.userInteractionEnabled = YES;
    [self addSubview:self.listImageV];
    [_listImageV release];
    
    UITapGestureRecognizer *tapLove = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapLove)];
    [self.loveImageV addGestureRecognizer:tapLove];
    [tapLove release];
    
    UITapGestureRecognizer *tapTurn = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapTurn)];
    [self.turnImageV addGestureRecognizer:tapTurn];
    [tapTurn release];
    
    UITapGestureRecognizer *tapSong = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapSong)];
    [self.songImageV addGestureRecognizer:tapSong];
    [tapSong release];
    
    UITapGestureRecognizer *tapShare = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapShare)];
    [self.shareImageV addGestureRecognizer:tapShare];
    [tapShare release];
    
    UITapGestureRecognizer *tapList = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapList)];
    [self.listImageV addGestureRecognizer:tapList];
    [tapList release];
}
- (void)tapList
{
    [self.delegate GetListView];
}
- (void)tapShare
{
    [self.delegate shareInPlayerView];
}
- (void)tapSong
{
    [self.delegate GetSonging];
}
- (void)tapTurn
{
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString *str = [user objectForKey:@"turn"];
    if ([str isEqual:@"list"])
    {
        self.turnImageV.image = [UIImage imageNamed:@"BF-danqu"];
        [user setObject:@"only" forKey:@"turn"];
        [self.delegate GetTurn];
    } else if ([str isEqual:@"only"]) {
        self.turnImageV.image = [UIImage imageNamed:@"BF-suiji"];
        [user setObject:@"arc" forKey:@"turn"];
        [self.delegate GetTurn];
    } else {
        self.turnImageV.image = [UIImage imageNamed:@"BF-liebiaoxunhuan"];
        [user setObject:@"list" forKey:@"turn"];
        [self.delegate GetTurn];
    }
}
- (void)tapLove
{
    if (0 == self.Lovenum)
    {
        self.loveImageV.image = [UIImage imageNamed:@"BF-love2"];
        self.Lovenum++;
    } else {
        self.loveImageV.image = [UIImage imageNamed:@"BF-love1"];
        self.Lovenum = 0;
    }
}
@end
